package io.bdmc.modules.bss.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.bdmc.common.annotation.SysLogger;
import io.bdmc.common.utils.R;
import io.bdmc.modules.bss.entity.DeviceRouteAlarmSetting;
import io.bdmc.modules.bss.service.IDeviceRouteAlarmSettingService;
import io.bdmc.modules.sys.controller.AbstractController;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 黄露
 * @since 2021-06-09
 */

// "路由OPM报警设置", description = "")
@RestController
@RequestMapping("/bss/route/setting")
public class DeviceRouteAlarmSettingController extends AbstractController {

    @Autowired
    IDeviceRouteAlarmSettingService alarmSettingService;

    @GetMapping("/list")
    // "分页查询", notes = "分页查询")
    public R list(Integer routeId) {
        if (routeId == null || routeId < 1) {
            return R.error("参数错误");
        }
        List<DeviceRouteAlarmSetting> settings = alarmSettingService
                .list(new QueryWrapper<DeviceRouteAlarmSetting>().eq("route_id", routeId));
        return R.ok().putData(settings);

    }

    @SysLogger("新增路由OPM报警设置")
    @PostMapping("/add")
    // "新增路由OPM报警设置", notes = "新增路由OPM报警设置")
    public R add(@RequestBody DeviceRouteAlarmSetting deviceroutealarmsetting) {
        Boolean b = deviceroutealarmsetting.insert();
        return R.trueOrFalse(b);
    }

    @SysLogger("修改路由OPM报警设置")
    @PostMapping("/update")
    // "修改路由OPM报警设置", notes = "修改路由OPM报警设置")
    public R update(@RequestBody DeviceRouteAlarmSetting deviceroutealarmsetting) {
        Boolean b = deviceroutealarmsetting.updateById();
        return R.trueOrFalse(b);
    }

    @SysLogger("删除路由OPM报警设置")
    @PostMapping("/delete")
    // "删除路由OPM报警设置", notes = "删除路由OPM报警设置")
    public R delete(@RequestBody Integer alarmSettingId) {
        if (alarmSettingId > 0)
            alarmSettingService.removeById(alarmSettingId);
        return R.ok();
    }
}
